package com.shihb.chapter03oop

/**
 * Apply的运用
 */
object Demo08Apply {
  def main(args: Array[String]): Unit = {

    val pig1 = new Pig("new的小猪")
    val pig2 = Pig()
    val pig3 = Pig("apply的小猪")
    println(pig1.name,pig2.name,pig3.name)
  }
}

class Pig(var name:String){}
object Pig{
  def apply(name: String): Pig = new Pig(name)
  def apply(): Pig = new Pig("默认小猪")
}
